package com.sqstudio.control
{
	import com.sqstudio.common.DataProxy;
	import com.sqstudio.common.ListCommander;
	import com.sqstudio.common.Sys;
	import com.sqstudio.event.CalendarEvent;
	import com.sqstudio.model.Model;
	import com.sqstudio.ui.LongBtn_FJAP;
	
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.geom.Point;

	public class HolidayController
	{
		private var _holidayBtn:LongBtn_FJAP;
		private var _holidayList:ListCommander;
		
		public function HolidayController()
		{
			this._holidayBtn = new LongBtn_FJAP();
			var dobj:DisplayObject = Sys.STAGE.addChild(this._holidayBtn);
			dobj.x = 320;
			dobj.y = 115;
			
			var listArr:Array = getListData();
			this._holidayList = new ListCommander(listArr[0],listArr[1],listCallBack,new Point(55,130));
			Sys.STAGE.addChild(this._holidayList);
			this._holidayList.visible = false;
			this._holidayList.y = 145;
			this._holidayList.x = 320;
			
			this._holidayBtn.addEventListener(MouseEvent.CLICK,ckHandler);
		}
		
		private function ckHandler(event:MouseEvent):void
		{
			this._holidayList.visible = !this._holidayList.visible;
			DataProxy.setIndex(this._holidayList);
		}
		
		private function getListData():Array{
			var labelArr:Array = new Array();
			var dataArr:Array = new Array();
			var xml:XML = DataProxy.holidayXML;
			for(var i:int=0;i<xml.holiday.length();i++){
				labelArr.push(String(xml.holiday[i].@name));
				dataArr.push(String(xml.holiday[i].@crtDate));
			}
			return [labelArr,dataArr];
		} 
		
		
		private function listCallBack($str:String):void{
			this._holidayList.visible = false;
			var nowDate:Date = new Date();
			Model.CrtDate = new Date(nowDate.getFullYear(),(int($str)/100-1),(int($str)%100));
			CalendarEvent.Dispatcher.dispatchEvent(new CalendarEvent(CalendarEvent.COUNT_CHANGE,1));
			CalendarEvent.Dispatcher.dispatchEvent(new CalendarEvent(CalendarEvent.DATE_CHANGE));		
		}
		

	}
}